<?php
require_once("../DAO/QuestionDAO.php");
require_once("../DAO/AnswerDAO.php");
require_once("../Entities/Question.php");
require_once("../Entities/Answer.php");
require_once("../DAO/TestDAO.php");
//type = 0 : get question theo category
//type = 1 : get description cua test

if(isset($_REQUEST["type"]))
{
	$type = $_REQUEST["type"];
	$questionDao = new QuestionDAO();
	$kqList = array();
	if($type == 0)
	{
		$id = $_REQUEST["id"]; // category id
		$page = $_REQUEST["page"];
		$totalPage = 0;
		$questions = $questionDao->GetQuestions($page, 10, $totalPage, $id);
		$kqList["count"] = count($questions);
		$kqList["totalPage"] = $totalPage;
		$kqList["list"] = $questions;
		echo json_encode($kqList);
	}
	else if($type == 1)
	{
		$id = $_REQUEST["id"]; // test id
		$testDAO = new TestDAO();
		$test = $testDAO->GetTestById($id);
		if($test == null)
		{
			$kqList["des"] = "don't find this test";
		}
		else
		{
			$kqList["des"] = $test->Description;
		}
		echo json_encode($kqList);
	}
}

?>